<include file="public@header" />
</head>
<style type="text/css">
	#file-wrap{
		height:34px;
		width: 82px;
		position: relative;
		display: inline-block;
		text-align: center;
		line-height: 34px;
		overflow: hidden;
		font-size: 14px;
		cursor: pointer;
		color: #fff;
		vertical-align: middle;
		background-color: #1a242f;
		border-color: #161f29;
	}
	#file-wrap input{
		position: absolute;
		height: 40px;
		z-index: 2;
		right: 0;
		top: 0;
		filter: alpha(opacity=0);
		-moz-opacity: 0;
		opacity: 0;
		cursor: pointer;
		font-size: 16px;
	}
</style>
<body>
<div class="wrap">
	<ul class="nav nav-tabs">
		<li><a href="{:url('version/index')}">版本列表</a></li>
		<li><a href="{:url('version/add')}">新版添加</a></li>
		<li class="active"><a>版本修改</a></li>
	</ul>
	<form method="post" class="form-horizontal js-ajax-form margin-top-20" action="{:url('version/editpost')}">
		<div class="form-group">
			<label for="input-v_number" class="col-sm-2 control-label"><span class="form-required">*</span>接口版本</label>
			<div class="col-md-6 col-sm-10">
                <input type="hidden" name="id" value="{$version.id}">
				<input type="text" class="form-control" id="input-v_number" name="v_number" maxlength="4" value="{$version.v_number}">
			</div>
		</div>
		<div class="form-group">
			<label for="input-v_digital" class="col-sm-2 control-label"><span class="form-required">*</span>版本号</label>
			<div class="col-md-6 col-sm-10">
				<input type="text" class="form-control" id="input-v_digital" name="v_digital" maxlength="8" value="{$version.v_digital}">
			</div>
		</div>
		<div class="form-group">
			<label for="input-v_forcibly" class="col-sm-2 control-label"><span class="form-required">*</span>强制更新</label>
			<div class="col-md-6 col-sm-10" id="input-v_forcibly">
				<select class="form-control" name="v_forcibly">
					<option value="10">是</option>
					<option value="20">否</option>
				</select>
			</div>
		</div>
		<div class="form-group">
			<label for="input-v_updatetime" class="col-sm-2 control-label"><span class="form-required">*</span>上线日期</label>
			<div class="col-md-6 col-sm-10">
				<input type="datetime" class="form-control js-bootstrap-datetime" id="input-v_updatetime" name="v_updatetime" value="{:substr($version['v_updatetime'],0,16)}">
			</div>
		</div>
		<div class="form-group">
			<label for="input-v_description" class="col-sm-2 control-label"><span class="form-required">*</span>说明</label>
			<div class="col-md-6 col-sm-10">
				<textarea class="form-control" id="input-v_description"  name="v_description" placeholder="发版说明">{$version.v_description}</textarea>
			</div>
		</div>
		<div class="form-group">
			<label for="input-v_type" class="col-sm-2 control-label"><span class="form-required">*</span>类型</label>
			<div class="col-md-6 col-sm-10" id="input-v_type">
				<input type="radio" name="v_type" value="10" onclick="link()"<if condition="$version['v_type'] eq 10" >checked </if>>iOS
				<input type="radio" name="v_type" value="20" onclick="link()"<if condition="$version['v_type'] eq 20" >checked </if>>Android
			</div>
		</div>
		<div class="form-group" id="android" <if condition="$version['v_type'] eq 10" >style="display: none" </if>>
			<label for="input-file" class="col-sm-2 control-label"><span class="form-required">*</span>文件</label>
			<div class="col-md-6 col-sm-10">
				<div id="file-wrap">
					<input type="file" onchange="upload(this)" accept=".apk" id="input-file" name="file" style="display: inline"/>
					选择文件
				</div>
				<p class="help-block">文件支持apk格式,文件大小最大不能超过32M</p>
				<input type="button" class="btn btn-default" id="cancel_file" onclick="cancel();" value="↓↓↓取消文件↓↓↓" style="display: none">
				<input type="hidden" name="path" id="path" value="">
                <input type="hidden" name="file" id="file" value="">
                <input type="hidden" name="link" value="{$version.v_link}">

			</div>
		</div>
		<div class="form-group">
			<label for="input-v_link" class="col-sm-2 control-label"><span class="form-required">*</span>链接</label>
			<div class="col-md-6 col-sm-10">
				<input type="text" class="form-control" id="input-v_link" name="v_link" value="{$version.v_link}">
				<p class="help-block">IOS请填写App Store地址、Android文件上传后会生成地址</p>
			</div>
		</div>
		<div class="form-group">
			<div class="col-sm-offset-2 col-sm-10">
				<button type="submit" class="btn btn-primary js-ajax-submit">修改</button>
			</div>
		</div>
	</form>
</div>
<script src="__STATIC__/js/admin.js"></script>
<script type="application/javascript">

    function link() {
        var intHot = $("input[name='v_type']:checked").val();
        if(intHot == 10){
            $('#android').attr('style','display: none');
            $('#input-v_link').attr('value','{$version.v_link}');
        }
        if(intHot == 20){
            $('#android').attr('style','display: block');
            $('#input-v_link').attr('value','');
        }
    }

    function cancel() {
        $('#file-wrap').show();
        $('#input-file').val('').attr('style','display: inline');
        $('#cancel_file').attr('style','display: none');
        $('#path').attr('value','');
        $('#file').attr('value','');
        $('#input-v_link').attr('value','');

    }

    function upload(obj) {
        var $fileinput = $(obj);
        Wind.css("jcrop");
        Wind.use("ajaxfileupload", "jcrop", "noty", function () {
            $.ajaxFileUpload({
                url: "{:url('version/uploadfile')}",
                secureuri: false,
                fileElementId: "input-file",
                dataType: 'json',
                data: {},
                success: function (data, status) {
                    if (data.code) {
                        $("#file-wrap").hide();
                        $('#cancel_file').show();
                        var src  = '{$simgs}'+ data.data.path + data.data.file;
                        $('#input-v_link').attr('value',src);
                        $('#path').attr('value',data.data.path);
                        $('#file').attr('value',data.data.file);
                    } else {
                        noty({
                            text: data.msg,
                            type: 'error',
                            layout: 'center',
                            callback: {
                                afterClose: function () {
                                    reloadPage(window);
                                }
                            }
                        });
                        cancel();
                    }
                },
                error: function (data, status, e) {
                    cancel();
                    alert(e + '\r文件错误。请重新选择！');
                }
            });
        });
        return false;
    }
</script>
</body>
</html>